<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <meta charset="UTF-8">
    <title>增加客户</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="stylesheet" type="text/css" href="/h-ui/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/h-ui.admin/css/H-ui.admin.css" />
    <link rel="stylesheet" type="text/css" href="/lib/Hui-iconfont/1.0.8/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="/h-ui.admin/css/style.css" />
    <![endif]-->
    <script type="text/javascript" src="/js/vue/vue.min.js"></script>
    <link rel="stylesheet" href="/js/laypage/skin/laypage.css">
    <script type="text/javascript" src="/js/laypage/laypage.js"></script>
    <link rel="stylesheet" href="/lib/layui/css/layui.css"  media="all">
</head>
<body>
<div class="page-container" data-validator-option="{theme:'simple_right'}">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="c-red">*</span>客户编号</label>
                <div class="layui-input-inline">
                    <input type="text" id="cus_number" name="cus_number" lay-verify="cus_number" autocomplete="off" class="layui-input">
                </div>
            </div>
            <input type="hidden" id="maxId" th:value="${session.maxId}">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="c-red">*</span>客户名称</label>
                <div class="layui-input-inline">
                    <input type="text" id="cus_compname" name="cus_compname" lay-verify="cus_compname" autocomplete="off" value="" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="c-red">*</span>联系人</label>
                <div class="layui-input-inline">
                    <input type="text" id="cus_name" name="cus_name" lay-verify="cus_name" autocomplete="off" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">关联人员</label>
                <div class="layui-input-inline">
                    <input type="text" id="cus_connname" name="cus_connname" lay-verify="cus_connname" autocomplete="off" value="" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="c-red">*</span>联系方式</label>
                <div class="layui-input-inline">
                    <input type="text" id="cus_tele" name="cus_tele" lay-verify="cus_tele" autocomplete="off" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="c-red">*</span>联系QQ</label>
                <div class="layui-input-inline">
                    <input type="text" id="cus_qq" name="cus_name" lay-verify="cus_qq" autocomplete="off" value="" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">公司地址</label>
                <div class="layui-input-inline">
                    <input type="text" id="cus_address" name="cus_address" lay-verify="cus_address" autocomplete="off" value="" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="c-red">*</span>公司邮箱</label>
                <div class="layui-input-inline">
                    <input type="text" id="cus_email" name="cus_email" lay-verify="cus_email" autocomplete="off" value="" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="c-red">*</span>应收欠款</label>
            <div class="layui-input-block">
                <input type="text" id="cus_money" name="cus_money" lay-verify="cus_money" autocomplete="off" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea placeholder="说点什么..." cols="5" rows="3" id="cus_remarks" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
                <button type="reset" id="cancelBtn" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script type="text/javascript" src="/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/lib/laypage/1.2/laypage.js"></script>
<script src="/lib/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var $ =layui.jquery;
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //自定义验证规则
        form.verify({
            cus_compname:function(value){
                if(value.length < 1){
                    return '客户名称不能为空啊';
                }
            },
            cus_money:function (value) {
                var check ='';
                if (value.length<1){
                    check='金额不能为空啊';
                };
                if (value.length>=1){
                    var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
                    var money = $('#cus_money').val();
                    if (!reg.test(money)){
                        check = '金额格式不对！'
                    }
                }
                return check;
            },
            cus_name:function (value) {
                if(value.length < 1){
                    return '联系人不能为空啊';
                }
            },
            cus_tele:function (value) {
                var check ='';
                if (value.length<1){
                    check='联系方式不能为空啊';
                };
                if (value.length>=1){
                    var reg=/^1[34578]\d{9}$/;
                    var tele = $('#cus_tele').val();
                    if (!reg.test(tele)){
                        check = '电话格式不对哦！'
                    }
                }
                return check;
            },
            cus_qq:function (value) {
                var check ='';
                if (value.length<1){
                    check='QQ不能为空啊';
                };
                if (value.length>=1){
                    var reg=/^\d{5,10}$/;
                    var qq = $('#cus_qq').val();
                    if (!reg.test(qq)){
                        check = 'QQ格式不对哦！'
                    }
                }
                return check;
            },
            cus_email:function (value) {
                var check ='';
                if (value.length<1){
                    check='邮箱不能为空啊';
                };
                if (value.length>=1){
                    var reg=/^[0-9a-zA-Z_.-]+[@][0-9a-zA-Z_.-]+([.][a-zA-Z]+){1,2}$/;
                    var email = $('#cus_email').val();
                    if (!reg.test(email)){
                        check = '邮箱格式不对哦！'
                    }
                }
                return check;
            }

        });
        function f() {
            var numList = "KH";
            //获取当前时间
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1;
            var day = date.getDate();
            if (month < 10) {
                month = "0" + month;
            }
            if (day < 10) {
                day = "0" + day;
            }
            var nowDate = year  + month  + day;
            var maxid =$("#maxId").val();
            numList += nowDate;
            numList += '00';
            numList += maxid;
            $("#cus_number").val(numList);
        }
        f();
        form.render();
        //监听提交
        form.on('submit(demo1)', function(){
            $.ajax({
                type: "post",
                dataType: "json",
                url: "/customermanagement/customer/insertCustomer",
                data: {
                    cusNumber: $("#cus_number").val(),
                    cusCompname: $("#cus_compname").val(),
                    cusMoney: $("#cus_money").val(),
                    cusTele: $("#cus_tele").val(),
                    cusName: $("#cus_name").val(),
                    cusFlag: 1,
                    cusConnname: $("#cus_connname").val(),
                    cusAddress: $("#cus_address").val(),
                    cusEmail: $("#cus_email").val(),
                    cusQq: $("#cus_qq").val(),
                    cusRemarks: $("#cus_remarks").val()
                },
                success: function(msg){
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            });
            return false;
        });
    });
</script>
</body>
</html>